package com.sentinel.demo03.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.sentinel.demo03.handler.MyBlockHandler;
import com.sentinel.demo03.service.HelloService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class HelloController {
    @Autowired
    private HelloService helloService;

    @GetMapping("/hello")
    @SentinelResource(
            value = "sayHi",
            blockHandler = "sayHiBlockHandler",
            blockHandlerClass = MyBlockHandler.class,
            fallback = "sayHiFallback",
            fallbackClass = MyBlockHandler.class
    )
    public String sayHi(String name) {
        log.info("sentinel-demo03 hello功能入参:{}", name);
        log.info("业务层注入的service对象:{}", helloService.getClass().getName());
        String result = helloService.sayHi(name);
        log.info("sentinel-demo03 hello功能出参:{}", result);
//        int a = 1/0;//模拟业务异常
        return result;
    }

}
